package model

import (
	"context"
	"fmt"

	"github.com/hwcer/yyds/options"
)

const (
	PlayerLikes = "likes"
)

var Likes = likes{}

type likes struct {
}

func (this *likes) Key(uid string) string {
	return fmt.Sprintf("%s_%d_%s", options.Options.Appid, options.Game.Sid, uid)
}

func (this *likes) Add(uid string, v int64) (int64, error) {
	cmd := Redis.HIncrBy(context.Background(), this.Key(uid), PlayerLikes, v)
	if e := cmd.Err(); e != nil {
		return 0, e
	}
	return cmd.Val(), nil
}
func (this *likes) Set(uid string, v int64) error {
	cmd := Redis.HSet(context.Background(), this.Key(uid), PlayerLikes, v)
	return cmd.Err()
}
func (this *likes) Get(uid string) (int64, error) {
	cmd := Redis.HGet(context.Background(), this.Key(uid), PlayerLikes)
	return cmd.Int64()
}
